package single;

import java.util.concurrent.atomic.AtomicReference;

/**
 * @Author longhj
 * @Description  CAS「AtomicReference」(线程安全)
 * @Date 2021/09/04 星期六 15:10
 */
public class CASThreadSafety {
    private CASThreadSafety() {

    }

    private static final AtomicReference<CASThreadSafety> REFERENCE = new AtomicReference<>();

    public static final CASThreadSafety getCasThreadSafety() {
        for (; ; ) {
            CASThreadSafety casThreadSafety = REFERENCE.get();
            if (null!=casThreadSafety) {
                return casThreadSafety;
            }
            REFERENCE.compareAndSet(null, new CASThreadSafety());
            return REFERENCE.get();
        }
    }
}
